<?php
GLOBAL $AppUI, $canEdit, $m, $tab,$typeTransportation;
$AppUI->savePlace();

/*if (! $canAccess) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}
*/
require_once("transportations.class.php");
$search_str = dPgetParam( $_REQUEST, 'search_string', '' );
$active = intval( dPgetParam( $_REQUEST, 'active', 1 ) );
$division = $_REQUEST['division'];
$costcenter = $_REQUEST['costcenter'];

require_once(DP_BASE_DIR."/modules/masterdata/mdstatus.class.php");
$status_list = getStatusList($typeTransportation);

require_once(DP_BASE_DIR."/modules/masterdata/mdtype.class.php");
$type_list = arrayMerge(array( '' => '--Select Type--' ),getTypeList($typeTransportation, TRUE));

require_once(DP_BASE_DIR."/modules/masterdata/mddivision.class.php");
$division_list = arrayMerge(array( '' => '--Select Division--' ),getDivisionList());

require_once(DP_BASE_DIR."/modules/masterdata/mdcostcenter.class.php");
$costcenter_list = arrayMerge(array( '' => '--Select Cost Center--' ),getCostCenterList());
// setup the title block

?>
<table width="100%" border="0" cellpadding="0" cellspacing="2" class="infopanel">
<tr>
<td width="4px">&nbsp;</td>
<td nowrap="nowrap">
<input type="button" class="button" value="<?=$AppUI->_('New Transportaions')?>" onclick="doEditTrans(0)"/>
</td>
<td align="right" width="100%">
<?=$AppUI->_('Search for')?>&nbsp;
<form action="index.php" method="get">
	<input type="hidden" name="m" value="<?=$m?>"/>
	<input type="hidden" name="tab" value="<?=$tab?>"/>
	<!--input type="hidden" name="u" value="transportations"/-->
</td>
<td>
	<input type="text" class="text" name="search_string" value="<?=$search_str?>" />
	<td>
		<?= arraySelect($division_list,'division','style="font-size:10px"',$division)?>
	</td>
	<td>
		<?= arraySelect($costcenter_list,'costcenter','style="font-size:10px"',$costcenter)?>
	</td>
</td>
<td>
	<input type="image" class="button" src="images/search.gif"/>
</form>
</td>
<td width="4px">&nbsp;</td>
</tr>
</table>
<table id="idTableMasterdata" class="list" width="100%" cellspacing="0" cellpadding="2" border="0">
<tbody>
<tr>

	<th nowrap="nowrap">&nbsp;</th>
	<!--th nowrap="nowrap"><?php echo $AppUI->_( 'Code' );?></th-->
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Name' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Status' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Type' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Division' );?></th>
	<th nowrap="nowrap"><?php echo $AppUI->_( 'Delete' );?></th>
</tr>

<?php
// retrieving some dynamic content using an easy database query
// add/show now gradually the einstein quotes
$q = new DBQuery();
$q->addTable('transportations');
$q->addJoin('md_status','','trans_status = status_id');
$q->addJoin('md_type','','trans_type = type_id');
$q->addJoin('divisions','','trans_division = div_id');
if($search_str!= null && $search_str!=''){
	$q->addWhere('trans_code like \'%'.$search_str.'%\'');
}
if($division!= null && $division!=''){
	$q->addWhere('trans_division = '.$division);
}
if($costcenter!= null && $costcenter!=''){
	$q->addWhere('trans_costcenter = '.$costcenter);
}
$q->addQuery('*');

$transportations  = $q->loadList();
if (empty($transportations)) {?>
<tr class="second">
<td colspan="100"><?php echo $AppUI->_( 'No item available' );?></td>
</tr>
<?php
}
$i = 0;
foreach ($transportations as $row) {		//parse the array of einstein quotes
	$i++;
?>
<tr class="<?=($i % 2 == 0) ? "second" : "first" ?>">
	<td nowrap="nowrap" width="20">


	<?php 	// in case of writePermission on the module show an icon providing edit functionality for the given quote item

		echo "\n".'<a onclick="doEditTrans('.$row["trans_id"]. ')">';
		echo dPshowImage( 'images/edit.gif' );
		echo "\n</a>";
	?>
	</td>
	<!--td> <?php echo $row["trans_code"];?></td-->
	<td><?php echo $row["trans_name"];?></td>
	<td><?php echo $row["status_name"];?></td>
	<td><?php echo $row["name"];?></td>
	<td><?php echo $row["div_name"];?></td>
	<td>
	<?php if ($canEdit) {
		showIconLink('images/delete.gif', 'js:doDelete('.$row["trans_id"]. ', \''.$row["trans_name"].'\')', 'Delete');
	}
	?>
	</td>
</tr>
<?php
}
?>
</tbody>
</table>
<div id="idTransDialog" class="popup" style="visibility: hidden; left: 436px; top: 94.5px; display: none;">
</div>
<script type="text/javascript" src="<?=DP_BASE_URL?>/modules/masterdata/transportations/transportations.module.js"></script>
<script type="text/javascript" language="javascript">
	Table("idTableMasterdata").setNormalHover(1);
</script>
<form name="MdFormDelete" id="MdFormDelete" action="?m=masterdata&u=transportations" method="post">
	<input type="hidden" name="dosql" value ="do_delete" />
	<input type="hidden" id="del_cc_id" name="trans_id" value ="" />
	<input type="hidden" name="del" value ="" />
</form>